.class public Lcom/glympse/platform/common/FavoriteList;
.super Ljava/lang/Object;
.source "FavoriteList.java"


# static fields
.field private static final FILE_NAME:Ljava/lang/String; = "favorites"


# instance fields
.field public m_listTickets:Lcom/glympse/platform/GVector$Tickets;

.field public m_oTicketComparator:Lcom/glympse/platform/common/Ticket$CompareByLastUseTime;


# direct methods
.method public constructor <init>()V
    .locals 1

    .prologue
    .line 19
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 23
    new-instance v0, Lcom/glympse/platform/GVector$Tickets;

    invoke-direct {v0}, Lcom/glympse/platform/GVector$Tickets;-><init>()V

    iput-object v0, p0, Lcom/glympse/platform/common/FavoriteList;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    .line 24
    new-instance v0, Lcom/glympse/platform/common/Ticket$CompareByLastUseTime;

    invoke-direct {v0}, Lcom/glympse/platform/common/Ticket$CompareByLastUseTime;-><init>()V

    iput-object v0, p0, Lcom/glympse/platform/common/FavoriteList;->m_oTicketComparator:Lcom/glympse/platform/common/Ticket$CompareByLastUseTime;

    .line 19
    return-void
.end method

.method private Save()V
    .locals 8

    .prologue
    const/4 v7, 0x0

    .line 124
    new-instance v2, Lcom/glympse/platform/GFile;

    invoke-direct {v2}, Lcom/glympse/platform/GFile;-><init>()V

    .line 125
    .local v2, oGFile:Lcom/glympse/platform/GFile;
    const-string v6, "favorites"

    invoke-virtual {v2, v6}, Lcom/glympse/platform/GFile;->OpenForOutput(Ljava/lang/String;)Z

    move-result v6

    if-nez v6, :cond_0

    .line 160
    :goto_0
    return-void

    .line 130
    :cond_0
    new-instance v5, Ljava/lang/StringBuffer;

    invoke-direct {v5}, Ljava/lang/StringBuffer;-><init>()V

    .line 132
    .local v5, strbuf:Ljava/lang/StringBuffer;
    iget-object v6, p0, Lcom/glympse/platform/common/FavoriteList;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    invoke-virtual {v6}, Lcom/glympse/platform/GVector$Tickets;->elements()Ljava/util/Enumeration;

    move-result-object v1

    .local v1, iterTicket:Ljava/util/Enumeration;
    :cond_1
    invoke-interface {v1}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v6

    if-nez v6, :cond_2

    .line 159
    invoke-virtual {v2}, Lcom/glympse/platform/GFile;->Close()V

    goto :goto_0

    .line 134
    :cond_2
    invoke-interface {v1}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v4

    check-cast v4, Lcom/glympse/platform/common/Ticket;

    .line 137
    .local v4, oTicketCur:Lcom/glympse/platform/common/Ticket;
    invoke-virtual {v5, v7}, Ljava/lang/StringBuffer;->setLength(I)V

    .line 138
    const/16 v6, 0x54

    invoke-virtual {v5, v6}, Ljava/lang/StringBuffer;->append(C)Ljava/lang/StringBuffer;

    .line 139
    invoke-virtual {v4, v5}, Lcom/glympse/platform/common/Ticket;->Serialize(Ljava/lang/StringBuffer;)V

    .line 142
    invoke-virtual {v5}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v6

    invoke-virtual {v2, v6}, Lcom/glympse/platform/GFile;->WriteLine(Ljava/lang/String;)Z

    .line 145
    iget-object v6, v4, Lcom/glympse/platform/common/Ticket;->m_listRecipients:Lcom/glympse/platform/GVector$Recipients;

    invoke-virtual {v6}, Lcom/glympse/platform/GVector$Recipients;->elements()Ljava/util/Enumeration;

    move-result-object v0

    .local v0, iterRecipient:Ljava/util/Enumeration;
    :goto_1
    invoke-interface {v0}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v6

    if-eqz v6, :cond_1

    .line 147
    invoke-interface {v0}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Lcom/glympse/platform/common/Recipient;

    .line 150
    .local v3, oRecipientCur:Lcom/glympse/platform/common/Recipient;
    invoke-virtual {v5, v7}, Ljava/lang/StringBuffer;->setLength(I)V

    .line 151
    const/16 v6, 0x52

    invoke-virtual {v5, v6}, Ljava/lang/StringBuffer;->append(C)Ljava/lang/StringBuffer;

    .line 152
    invoke-virtual {v3, v5}, Lcom/glympse/platform/common/Recipient;->Serialize(Ljava/lang/StringBuffer;)V

    .line 155
    invoke-virtual {v5}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v6

    invoke-virtual {v2, v6}, Lcom/glympse/platform/GFile;->WriteLine(Ljava/lang/String;)Z

    goto :goto_1
.end method


# virtual methods
.method public Add(Lcom/glympse/platform/common/Ticket;Ljava/lang/String;)V
    .locals 3
    .parameter "oTicket"
    .parameter "strName"

    .prologue
    .line 42
    if-eqz p1, :cond_0

    .line 45
    new-instance v0, Lcom/glympse/platform/common/Ticket;

    invoke-direct {v0, p1}, Lcom/glympse/platform/common/Ticket;-><init>(Lcom/glympse/platform/common/Ticket;)V

    .line 48
    .local v0, oTicketCopy:Lcom/glympse/platform/common/Ticket;
    invoke-static {p2}, Lcom/glympse/platform/common/Helpers;->SafeStr(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    iput-object v1, v0, Lcom/glympse/platform/common/Ticket;->m_strName:Ljava/lang/String;

    .line 51
    invoke-static {}, Lcom/glympse/platform/common/CorrectedTime;->GetTime()J

    move-result-wide v1

    iput-wide v1, v0, Lcom/glympse/platform/common/Ticket;->m_lLastUseTime:J

    .line 54
    iget-object v1, p0, Lcom/glympse/platform/common/FavoriteList;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    const/4 v2, 0x0

    invoke-virtual {v1, v0, v2}, Lcom/glympse/platform/GVector$Tickets;->insertElementAt(Ljava/lang/Object;I)V

    .line 57
    iget-object v1, p0, Lcom/glympse/platform/common/FavoriteList;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    iget-object v2, p0, Lcom/glympse/platform/common/FavoriteList;->m_oTicketComparator:Lcom/glympse/platform/common/Ticket$CompareByLastUseTime;

    invoke-virtual {v1, v2}, Lcom/glympse/platform/GVector$Tickets;->Sort(Lcom/glympse/platform/GComparator;)V

    .line 60
    invoke-direct {p0}, Lcom/glympse/platform/common/FavoriteList;->Save()V

    .line 62
    .end local v0           #oTicketCopy:Lcom/glympse/platform/common/Ticket;
    :cond_0
    return-void
.end method

.method protected Clear()V
    .locals 1

    .prologue
    .line 118
    iget-object v0, p0, Lcom/glympse/platform/common/FavoriteList;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    invoke-virtual {v0}, Lcom/glympse/platform/GVector$Tickets;->removeAllElements()V

    .line 119
    return-void
.end method

.method public FindMatch(Lcom/glympse/platform/common/Ticket;)Lcom/glympse/platform/common/Ticket;
    .locals 3
    .parameter "oTicket"

    .prologue
    .line 104
    iget-object v2, p0, Lcom/glympse/platform/common/FavoriteList;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    invoke-virtual {v2}, Lcom/glympse/platform/GVector$Tickets;->elements()Ljava/util/Enumeration;

    move-result-object v0

    .local v0, iterTicket:Ljava/util/Enumeration;
    :cond_0
    invoke-interface {v0}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v2

    if-nez v2, :cond_1

    .line 111
    const/4 v2, 0x0

    :goto_0
    return-object v2

    .line 106
    :cond_1
    invoke-interface {v0}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lcom/glympse/platform/common/Ticket;

    .line 107
    .local v1, oTicketCur:Lcom/glympse/platform/common/Ticket;
    invoke-virtual {v1, p1}, Lcom/glympse/platform/common/Ticket;->Compare(Lcom/glympse/platform/common/Ticket;)Z

    move-result v2

    if-eqz v2, :cond_0

    move-object v2, v1

    .line 108
    goto :goto_0
.end method

.method public Load()V
    .locals 9

    .prologue
    .line 166
    new-instance v1, Lcom/glympse/platform/GFile;

    invoke-direct {v1}, Lcom/glympse/platform/GFile;-><init>()V

    .line 167
    .local v1, oGFile:Lcom/glympse/platform/GFile;
    const-string v6, "favorites"

    invoke-virtual {v1, v6}, Lcom/glympse/platform/GFile;->OpenForInput(Ljava/lang/String;)Z

    move-result v6

    if-eqz v6, :cond_1

    .line 170
    const/4 v0, 0x0

    .line 171
    .local v0, listNameValues:Lcom/glympse/platform/GVector$NameValueNodes;,"Lcom/glympse/platform/GVector$NameValueNodes;"
    :cond_0
    :goto_0
    invoke-virtual {v1}, Lcom/glympse/platform/GFile;->ReadLine()Lcom/glympse/platform/GVector$NameValueNodes;

    move-result-object v0

    if-nez v0, :cond_2

    .line 204
    .end local v0           #listNameValues:Lcom/glympse/platform/GVector$NameValueNodes;,"Lcom/glympse/platform/GVector$NameValueNodes;"
    :cond_1
    invoke-virtual {v1}, Lcom/glympse/platform/GFile;->Close()V

    .line 205
    return-void

    .line 173
    .restart local v0       #listNameValues:Lcom/glympse/platform/GVector$NameValueNodes;,"Lcom/glympse/platform/GVector$NameValueNodes;"
    :cond_2
    const/4 v6, 0x0

    invoke-virtual {v0, v6}, Lcom/glympse/platform/GVector$NameValueNodes;->elementAt(I)Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lcom/glympse/platform/common/NameValueNode;

    .line 176
    .local v2, oNameValueNode:Lcom/glympse/platform/common/NameValueNode;
    iget-object v6, v2, Lcom/glympse/platform/common/NameValueNode;->m_strValue:Ljava/lang/String;

    const-string v7, "T"

    invoke-virtual {v6, v7}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v6

    if-eqz v6, :cond_3

    .line 179
    new-instance v4, Lcom/glympse/platform/common/Ticket;

    invoke-direct {v4}, Lcom/glympse/platform/common/Ticket;-><init>()V

    .line 182
    .local v4, oTicket:Lcom/glympse/platform/common/Ticket;
    invoke-virtual {v4, v0}, Lcom/glympse/platform/common/Ticket;->Parse(Lcom/glympse/platform/GVector$NameValueNodes;)V

    .line 185
    iget-object v6, p0, Lcom/glympse/platform/common/FavoriteList;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    invoke-virtual {v6, v4}, Lcom/glympse/platform/GVector$Tickets;->addElement(Ljava/lang/Object;)V

    goto :goto_0

    .line 189
    .end local v4           #oTicket:Lcom/glympse/platform/common/Ticket;
    :cond_3
    iget-object v6, v2, Lcom/glympse/platform/common/NameValueNode;->m_strValue:Ljava/lang/String;

    const-string v7, "R"

    invoke-virtual {v6, v7}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v6

    if-eqz v6, :cond_0

    iget-object v6, p0, Lcom/glympse/platform/common/FavoriteList;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    invoke-virtual {v6}, Lcom/glympse/platform/GVector$Tickets;->isEmpty()Z

    move-result v6

    if-nez v6, :cond_0

    .line 192
    new-instance v3, Lcom/glympse/platform/common/Recipient;

    invoke-direct {v3}, Lcom/glympse/platform/common/Recipient;-><init>()V

    .line 195
    .local v3, oRecipient:Lcom/glympse/platform/common/Recipient;
    invoke-virtual {v3, v0}, Lcom/glympse/platform/common/Recipient;->Parse(Lcom/glympse/platform/GVector$NameValueNodes;)V

    .line 198
    iget-object v6, p0, Lcom/glympse/platform/common/FavoriteList;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    iget-object v7, p0, Lcom/glympse/platform/common/FavoriteList;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    invoke-virtual {v7}, Lcom/glympse/platform/GVector$Tickets;->size()I

    move-result v7

    const/4 v8, 0x1

    sub-int/2addr v7, v8

    invoke-virtual {v6, v7}, Lcom/glympse/platform/GVector$Tickets;->elementAt(I)Ljava/lang/Object;

    move-result-object v5

    check-cast v5, Lcom/glympse/platform/common/Ticket;

    .line 199
    .local v5, oTicketLast:Lcom/glympse/platform/common/Ticket;
    iget-object v6, v5, Lcom/glympse/platform/common/Ticket;->m_listRecipients:Lcom/glympse/platform/GVector$Recipients;

    invoke-virtual {v6, v3}, Lcom/glympse/platform/GVector$Recipients;->addElement(Ljava/lang/Object;)V

    goto :goto_0
.end method

.method public MoveToTop(Lcom/glympse/platform/common/Ticket;)V
    .locals 2
    .parameter "oTicket"

    .prologue
    .line 68
    iget-object v0, p0, Lcom/glympse/platform/common/FavoriteList;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    invoke-virtual {v0, p1}, Lcom/glympse/platform/GVector$Tickets;->removeElement(Ljava/lang/Object;)Z

    .line 69
    iget-object v0, p0, Lcom/glympse/platform/common/FavoriteList;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    const/4 v1, 0x0

    invoke-virtual {v0, p1, v1}, Lcom/glympse/platform/GVector$Tickets;->insertElementAt(Ljava/lang/Object;I)V

    .line 72
    invoke-direct {p0}, Lcom/glympse/platform/common/FavoriteList;->Save()V

    .line 73
    return-void
.end method

.method public Remove(Lcom/glympse/platform/common/Ticket;)Z
    .locals 1
    .parameter "oTicket"

    .prologue
    .line 79
    iget-object v0, p0, Lcom/glympse/platform/common/FavoriteList;->m_listTickets:Lcom/glympse/platform/GVector$Tickets;

    invoke-virtual {v0, p1}, Lcom/glympse/platform/GVector$Tickets;->removeElement(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 82
    invoke-direct {p0}, Lcom/glympse/platform/common/FavoriteList;->Save()V

    .line 84
    const/4 v0, 0x1

    .line 87
    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method

.method public Rename(Lcom/glympse/platform/common/Ticket;Ljava/lang/String;)V
    .locals 0
    .parameter "oTicket"
    .parameter "strName"

    .prologue
    .line 93
    if-eqz p1, :cond_0

    .line 95
    iput-object p2, p1, Lcom/glympse/platform/common/Ticket;->m_strName:Ljava/lang/String;

    .line 96
    invoke-direct {p0}, Lcom/glympse/platform/common/FavoriteList;->Save()V

    .line 98
    :cond_0
    return-void
.end method

.method public Start()V
    .locals 0

    .prologue
    .line 29
    invoke-virtual {p0}, Lcom/glympse/platform/common/FavoriteList;->Clear()V

    .line 30
    invoke-virtual {p0}, Lcom/glympse/platform/common/FavoriteList;->Load()V

    .line 31
    return-void
.end method

.method public Stop()V
    .locals 0

    .prologue
    .line 36
    invoke-virtual {p0}, Lcom/glympse/platform/common/FavoriteList;->Clear()V

    .line 37
    return-void
.end method
